<template>
	<view>
		<!-- 404页面 -->
		<view class="noData" v-if="netWorkType == 'none'">
			<noData @handle="refresh"></noData>
		</view>
		<view v-if="netWorkType != 'none'">

			<!-- <view class="header-box">
		<view class="left">
			<view @tap="selectMonth" class="month">
				<view class="left">{{monthList.text}}</view>
				<view class="right"><view class="iconfont">&#xe6a2;</view></view>
			</view>
		</view>
		
	</view> -->
			<scroll-view scroll-x scroll-with-animation class="tab-view" :scroll-left="scrollLeft">

				<view v-for="(item,index) in tabbar" class="tab-bar-item" :data-current="index" @tap.stop="swichNav">
					<text class="tab-bar-title"
						:class="[currentTab==index ? 'theme-color active theme-boder' : '']">{{item}}</text>
				</view>
			</scroll-view>
			<!-- recharge_icon.png 充值余额   pay_icon  支付   cash_icon  提现   -->
			<!-- 新列表 -->
			<view class="newswiper">
				<view class="row-box" v-for="(item,index) in data.list" :key="index" style="width: 100%;">
					<view class="row-boxin">
						<view class="row-header">
							<!-- 租赁时间 -->
							<view class="left">
								{{item.create_time}}
							</view>
							<!-- 租赁状态 -->
							<view class="right theme-color">
								{{item.estateName}}
							</view>
						</view>
						<view class="row-mod">
							<view class="left">
								<!-- 商品图片 -->
								<view class="img-box">
									<image :src="item.cover_image" mode="widthFix" style="width: 100%;"></image>
								</view>

							</view>
							<view class="right">
								<!-- 商品名字 -->
								<view class="name">
									{{item.name}}
								</view>
								<view class="time">
									<view class="term">
										套餐期限：<text v-if="item.month_card_order_id>0"> {{item.use_expire_at}}</text>
										<text v-else> 无套餐</text>
									</view>

									<view class="lease-time">
										已租赁： {{item.use_day}}天
									</view>
								</view>
								<view class="beyond-price">
									<text>超出套餐价格： {{item.price}}/天</text>
									<!-- <text v-else>价格： {{item.price}}</text> -->
								</view>
								<!-- <view class="delivery-fee" v-if="item.apply_time!=''">
							配送费： {{item.deliver_fee}}
						</view> -->
								<view class="apply-time">
									配送费：自提
								</view>
								<!-- 判断是否已免押 -->
								<view class="deposit">
									押金：<text :class="item.related_type==3?'text-line-through':''"> {{item.cash}}</text>
									<text class="theme-color" v-if="item.related_type==3">(已免押)</text>
								</view>
								<view class="price">
									<view class="all-price">
										总价：￥{{item.count_fee}}
									</view>
									<!-- 判断有没有优惠 -->
									<view class="discount" v-if="item.discount_fee>0">
										优惠：￥{{item.discount_fee}}
									</view>
									<view class="actual-price">
										实付款：￥{{item.count}}
									</view>
								</view>
							</view>
						</view>
						<view class="row-pay" v-if="maintain_estate!=4">
							<view class="left">
								<view class="icon iconfont">
									&#xe628;
								</view>
								<view class="text">
									{{item.store_name}}
								</view>
							</view>
							<view class="right">
								<view class="details-btn" v-if="item.order_estate=='used_pending_payment'"
									@tap="lossPayPop(item.id,item.name,item.self_custom_amount,item.cash,item.related_type)">
									赔付
								</view>
								<view class="cost-btn block" v-if="item.order_estate=='used_pending_payment'"
									@tap="getPayStore(item)">
									归还
								</view>
								<view class="complete" v-if="item.order_estate=='completed'">
									已完成
								</view>
							</view>
						</view>


					</view>
				</view>
			</view>
			<!-- 新列表结束 -->
			<!-- 列表 -->
			<!-- <view class="swiper">
		<tui-list-cell v-for="(item,index) in data.list" :key="index"  :arrow="false" class="tui-list">
			<view class="tui-msg-box">
				<view class="row">{{item.name}}</view>
				<view class="row">
					<view class="left">
						<view style="color:#595556;" class="iconfont">&#xe6d3;</view>
					</view>
					<view class="right">{{item.create_time}}</view>
				</view>
				<view class="row">
					<view class="left">
						<view style="color:#F0A554;" class="iconfont">&#xe60a;</view>
					</view>
					<view class="right">{{item.store_name}}</view>
					
				</view> 
				<view v-if="item.month_card_order_id>0" class="row">
					<view class="left">
						<view style="color:#9BD4B0;" class="iconfont">&#xe6d3;</view>
					</view>
					<view class="right">月卡到期:{{item.use_expire_at}}</view>
				</view>
				<view class="row">
					<view class="left">
						<view style="color:#9BD4B0;" class="iconfont">&#xe6d3;</view>
					</view>
					<view class="right">{{item.use_day}}天</view>
				</view>
				<view v-if="item.used_promotion_estate" class="row">
					<view class="left">
						<view style="color:#EE8D73;" class="iconfont">&#xe60a;</view>
					</view>
					<view class="right">推广活动优惠<text style="color:#ED3F14;">{{item.activity_fee}}</text>元</view>
				</view>
				
				<view class="row">
					<view class="left">
						<view style="color:#EE8D73;" class="iconfont">&#xe60a;</view>
					</view>
					<view class="right">{{item.rent_fee}}元</view>
				</view>
				<view v-if="item.order_estate!='completed'" class="row">
					<view class="left">
						<view style="color:#EE8D73;" class="iconfont">&#xe60a;</view>
					</view>
					<view class="right">
						轮椅不见了
						<text @tap="lossPayPop(item.id,item.name,item.self_custom_amount,item.cash,item.related_type)" class="loss-pay theme-color">>>>立即赔付</text>
					</view>
				</view>
			</view>
			<view class="tui-msg-right">
				<view v-if="item.order_estate=='completed'" class="tui-msg-tip msg-active">已完成</view>
				<view v-if="item.order_estate=='used_pending_payment'" class="tui-msg-tip msg-active">
					<view @tap="getPayStore(item.id,item.name,item.use_day,item.rent_fee,item.related_type)" style="font-size: 80upx;color: #69a4fe;" class="iconfont">&#xe78c;</view>
				</view>
			
			</view>
		</tui-list-cell>
	</view> -->
			<!-- 商品租赁弹框    开始-->
			<uni-popup ref="nearbyStore" :type="type" :custom="true">
				<view class="carts-list">
					<tui-list-cell :arrow="false" class="tui-list">
						<view class="tui-msg-box show-title">
							租赁-{{editName}}
						</view>
					</tui-list-cell>
					<tui-list-cell :arrow="false" class="tui-list">
						<view class="tui-msg-box">
							<view class="row">
								<view class="left">
									<view class="icon iconfont theme-color">
										&#xe628;
									</view>
									<text>租借门店</text>

								</view>
							</view>
							<view class="row">
								<view class="left">
									<text>{{storeName}}</text>

								</view>
							</view>
						</view>
					</tui-list-cell>
					<!-- <tui-list-cell   :arrow="false" class="tui-list">		
				<view class="tui-msg-box">	
					<view class="row">
						<view class="left">
						<view class="icon iconfont theme-color">
							&#xe677;
						</view>
						<text>归还门店</text>
						
						</view>	
						
					</view>
					<radio-group @change="radioChange">
						<view v-for="(item,index) in data.nearbyStore" class="row">
							<view class="left">
								
								<text>{{item.store_name}}</text>
							</view>
							<view class="right" >					
								<radio style="transform: scale(0.7)" :value="item.id" :checked="index === current"></radio>				
							</view>
						</view>	
						<view v-if="data.nearbyStore.length===0" class="row">
							<view class="left">
								
								<text>附近无可选门店</text>
							</view>				
						</view>	
					</radio-group>
				</view>		
			</tui-list-cell> -->

					<tui-list-cell :arrow="false" class="tui-list" @click="seleteStore">
						<view class="tui-msg-box">
							<view class="row">
								<view class="left">
									<view class="icon iconfont theme-color">
										&#xe677;
									</view>
									<text>归还门店</text>

								</view>

							</view>
							<view>
								<view class="row" v-if="data.nearbyStore.length!==0">
									<view class="left">

										<text v-if="data.storeaddress.store_name==undefined">请选择门店</text>
										<text v-else>{{data.storeaddress.store_name}}</text>
									</view>
									<view class="right">
									</view>
								</view>
								<view v-if="data.nearbyStore.length===0" class="row">
									<view class="left">

										<text>附近无可选门店</text>
									</view>
								</view>
							</view>
						</view>
					</tui-list-cell>

					<tui-list-cell :arrow="false" class="tui-list">
						<view class="tui-msg-box">
							<view class="row">
								<view class="mod">
									租赁天数： {{editUseDay}}天
								</view>
							</view>
							<view class="row">
								<!-- 这里和套餐一样需要判断 -->
								<view class="mod">
									费用：<text class="redColor"> {{editFee}}</text>
								</view>
							</view>
							<view class="row">
								<view class="mod">
									<!-- 押金：<text class="redColor"> {{editCash}}</text> -->
									押金：<text class="redColor" :class="editRelatedType==3?'text-line-through':''">
										{{editCash}}</text>
									<text class="redColor" v-if="editRelatedType==3">(已免押)</text>
								</view>
							</view>
							<view class="row">
								<!-- 这里和套餐一样需要判断 -->
								<view class="mod">
									超时费用：<text class="redColor"> {{editOutFee}}</text>
								</view>
							</view>
							<view class="row">
								<view class="mod">
									调度费：<text class="redColor"> {{editDispatchFee}}</text>
								</view>
							</view>
							<view class="row">
								<!-- <view class="mod">					
							配送费：<text class="redColor"> {{editUseDay}}</text>		
						</view> -->
							</view>
						</view>
					</tui-list-cell>
					<!-- 优惠卷 -->
					<tui-list-cell @click="useCoupon" :arrow="true" class="tui-list">
						<view class="tui-msg-box">
							<view class="row" style="padding-right: 40rpx;width: auto;">
								<view class="left">
									<view class="icon iconfont" style="color: #fe9b69;">
										&#xe674;
									</view>
									<text v-if="couponId&&editCount>parseInt(couponMoney)">{{couponName}}</text>
									<text v-else>优惠卷</text>
								</view>
								<view v-if="couponId&&editCount>parseInt(couponMoney)" class="right redColor">
									￥-{{couponMoney}}
								</view>
							</view>
						</view>
					</tui-list-cell>

					<view v-if="couponId>0&&editCount>parseInt(couponMoney)" class="tui-msg-box all-price-red">
						总计：<text class="redColor"> ￥{{editCount-parseInt(couponMoney)}}</text>
					</view>
					<view v-else class="tui-msg-box all-price-red">
						总计：<text class="redColor"> ￥{{editCount}}</text>
					</view>
					<view class="show-button">
						<button @tap="closePopup" type="primary" class="close">取消</button>
						<button @tap="pay" type="primary">支付</button>
					</view>
				</view>
			</uni-popup>
			<!-- 商品租赁弹框    结束-->
			<!-- 赔付弹框    开始-->
			<uni-popup ref="lossPopup" :type="type" :custom="true">
				<view style="height:450upx;" class="carts-list">
					<view class="show-title">丢失产品-{{lossProductName}}</view>

					<tui-list-cell :arrow="false" class="tui-list">
						<view class="tui-msg-box">
							<view class="row">
								<view style="width: 50upx;display: none;" class="left">
									<view style="color:#EE8D73;font-size: ;" class="iconfont">&#xe60a;</view>
								</view>
								<view class="right">
									赔付 <text class="redColor">{{lossSelfCustomAmount}}</text> 元
								</view>
							</view>
						</view>
					</tui-list-cell>
					<view class="show-button">
						<button @tap="closePopup" type="primary" class="close">取消</button>
						<button @tap="lossPay" type="primary">赔付</button>
					</view>
				</view>

			</uni-popup>

			<!-- 赔付弹框    结束-->
			<!-- 优惠卷弹窗 -->

			<coupon-popup ref="couponPopup" :couponList='data.couponList' :show='showCouponPopup' :couponId='couponId'
				@getOverAndSale='getOverAndSale' @maskClose='maskClose'>
				<!-- <view slot='coupon-type'>
			<text @tap="couponTab(index)" :class="active==index ? 'active' : ''" v-for="(item,index) in tabCouponArr" :key="index">
			{{item.label}}
			</text>
		</view> -->
				<view slot='close-coupon-popup' @click="closeCouponPopup">x</view>

				<!-- <button @click="saveCoupon" v-if="couponList.length>0" slot='coupon-footer-complete' type="primary" size="default">确定</button>
	 -->
			</coupon-popup>
			<!-- 优惠卷弹窗end -->
			<!-- 提示弹框 -->
			<tui-tips ref="toast"></tui-tips>
			<uni-load-more :loadingType="loadingType" :contentText="contentText"></uni-load-more>
			<!-- 登录弹框 -->
			<uni-popup-vlogin id="popupvLogin" ref="popupvLogin" type="bottom" />
			<!-- 共用底部 -->
			<!-- <btabbar></btabbar> -->
			<!-- 共用底部end1 -->
			<btabbar></btabbar>
		</view>
	</view>

</template>

<script>
	// cj引入优惠卷弹窗
	import couponPopup from "@/components/coupon-popup/coupon-popup"
	import {
		compare
	} from '@/utils/base.js' //降序函数
	//#ifdef  H5
	let jweixin = require('jweixin-module')
	//#endif	
	import tuiListCell from "@/components/list-cell/list-cell"
	import uniPopup from '@/components/uni-popup/uni-popup.vue'

	import mpvuePicker from '@/components/mpvue-picker/mpvuePicker.vue'
	//底部
	import btabbar from '@/components/orderBottomTable/orderBottomTable.vue'
	// import btabbar from '@/components/indexBottomTable/bottomtabbar.vue'
	//下拉组件
	import uniLoadMore from '@/components/uni-load-more.vue';
	import store from '@/store/index.js';
	import {
		mapGetters
	} from 'vuex';
	import Vue from 'vue'
	export default {
		data() {
			return {
				couponObj: {},
				showCouponPopup: false, //优惠券弹窗
				tabbar: ["全部", "租赁中", "已完成"],
				winHeight: "", //窗口高度
				currentTab: 0, //预设当前项的值
				scrollLeft: 0, //tab标题的滚动条位置
				loadingText: '加载中...',
				loadingType: 3, //定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore 3-----contentfirst
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了',
					contentfirst: "暂无数据"
				},
				curr_page: 0, //当前页
				last_page: 0, //总页数
				//接口数据
				data: {
					list: [],
					info: {},
					nearbyStore: [],
					isFree: 0,
					storeaddress: {},
					couponList: [],
				},
				//订单类型
				order_estate: '',
				//下拉数据
				monthList: {
					text: '本月',
					key: 0,
					val: 0
				},
				//edit
				editId: '',
				editName: '',
				storeName: '',
				editUseDay: '',
				editRentFee: 0,
				editRelatedType: 0,
				editPrice: 0,
				editCount: 0,
				editCash: 0,
				editFee: 0,
				editOutFee: 0,
				editDispatchFee: 0,
				editStoreId: 0, //租赁门店id
				//orther param
				lossProductName: '', //丢失产品名称
				lossOrderId: '',
				lossSelfCustomAmount: '',
				lossRelatedType: '',
				cartsListHeight: 270, //动态高度
				calcullateHeight: 270, //固定高度，计算需要
				type: 'bottom',
				//当前选中的门店
				current: 0,
				latitude: '',
				longitude: '',
				//请求支付URL
				url: [
					'/order/pay',
					'/order/freeCashPay'
				],
				//优惠券
				couponId: null,
				couponName: '优惠券',
				couponMoney: 0
			}
		},
		components: {
			uniPopup,
			tuiListCell,
			mpvuePicker,
			uniLoadMore,
			btabbar,
			couponPopup
		},
		computed: {
			...mapGetters(['netWorkType', 'loginStatus'])
		},
		onLoad: function() {
			let that = this;
			//  高度自适应
			uni.getSystemInfo({
				success: function(res) {
					let calc = res.windowHeight;
					that.winHeight = calc;
				}
			});
			//#ifdef  H5
			//初始公众号配置
			service.initWxH5Config()
			//#endif

		},
		onShow() {
			this.curr_page = 0
			this.getList()
			//设置门店自提地址
			uni.getStorage({
				key: 'seleteStore',
				success: (e) => {
					//console.log(e)
					this.data.storeaddress = e.data;
					this.data.nearbyStore = e.data;
					console.log("huoqu配送")
					//console.log(this.data.address)
					// uni.removeStorage({
					// 	key:'selectAddress'
					// })deliverStoreObj.val
				},
				fail: () => {
					//初始默认地址
					console.log("huoqu无配送")
				}
			})
			//优惠券
			uni.getStorage({
				key: 'selectCoupon',
				success: (e) => {
					//console.log(e)	
					this.couponId = e.data.coupon_id
					this.couponName = e.data.name
					this.couponMoney = e.data.coupon_money

				}
			})



		},
		onPullDownRefresh: function() {
			//下拉刷新的时候请求一次数据
			//console.log(11)
			this.curr_page = 0
			this.loadingType = 3;
			this.getList();
		},
		onReachBottom: function() {
			//触底的时候请求数据，即为上拉加载更多
			//为了更加清楚的看到效果，添加了定时器

			if (this.curr_page >= this.last_page) {
				uni.showToast({
					icon: 'none',
					title: '没有更多数据'
				});

				this.loadingType = 2;
				return;
			}

			this.loadingType = 1;
			// 正常应为:
			this.getList();
		},
		methods: {
			camera() {
				const _this = this
				if (!_this.loginStatus) {
					_this.$refer.setVilit('local')
					let callback = function(url) {

						_this.$refs.popupvLogin.open()

					}

					_this.$refer.toUrl(callback, {}, 'local')
				} else {
					//授权手机    必须
					//console.log('camera')
					//#ifdef  H5
					//console.log(99)
					jweixin.getLocation({
						type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
						success: function(res) {
							_this.latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
							_this.longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。

							// if(_this.data.userInfo.mobile===''&&_this.data.userInfo.ali_mobile==='')
							// {					
							// 	return
							// }
							jweixin.scanQRCode({
								needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
								scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
								success: function(res) {
									let url = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
									//门店id
									const sid = _this.getQueryVariable('sid', url)

									//商品supply_id  其它时候是商品id
									const pid = _this.getQueryVariable('pid', url)

									//商家id
									const bid = _this.getQueryVariable('bid', url)

									//产品类型id
									const cid = _this.getQueryVariable('cid', url)


									_this.getProduct(sid, pid, bid, cid)
								}
							});
						}
					});



					//#endif	

					//#ifdef  MP-WEIXIN || MP-ALIPAY ||APP-PLUS

					uni.getLocation({
						//#ifdef  MP-WEIXIN ||APP-PLUS
						type: 'gcj02', //返回可以用于uni.openLocation的经纬度
						//#endif

						success: function(res) {

							_this.latitude = res.latitude;
							_this.longitude = res.longitude;
							// 记得关掉
							// _this.latitude = 22.797131;
							// _this.longitude = 108.339878;
							//22.797131,108.339878

							// if(_this.data.userInfo.mobile===''&&_this.data.userInfo.ali_mobile==='')
							// {

							// 	return
							// }

							uni.scanCode({
								onlyFromCamera: true,
								success: function(res) {
									//console.log(res)
									//console.log('条码类型：' + res.scanType);
									const code = res.result
									// console.log('条码内容：' + res.result);
									if (res.scanType == 'EAN_13') {
										//console.log(code)
										//条形码     进入产品绑定页
										// uni.navigateTo({
										//     url: '../after_sales/manager/manager?code='+code
										// });

										// return
										console.log(code)
										_this.$refer.setVilit('/pages/after_sales/manager/manager')
										let callback = function(url) {
											_this.$refs.popupvLogin.open()
										}
										var data = {
											code: code
										}

										_this.$refer.toUrl(callback, data)
										return
									}

									if (res.scanType == 'QR_CODE') {
										//门店id
										const sid = _this.getQueryVariable('sid', code)

										//商品supply_id  其它时候是商品id
										const pid = _this.getQueryVariable('pid', code)

										//商家id
										const bid = _this.getQueryVariable('bid', code)

										//产品类型id
										const cid = _this.getQueryVariable('cid', code)


										_this.getProduct(sid, pid, bid, cid)
										// _this.seleteStore(sid,pid,bid,cid)
										return
									}


								}
							});

						},
						fail: function(res) {
							let options = {
								msg: 'GPS未开启',
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
							_this.cashModal = true

							return
						}
					});
					//#endif
				}
			},
			// 关闭优惠卷弹窗
			closeCouponPopup() {
				this.showCouponPopup = false;
			},
			maskClose(data) {
				this.showCouponPopup = data;
			},
			getOverAndSale(data) {
				// 点击子组件传过来的值
				this.showCouponPopup = false;
				console.log(data)
				this.couponName = data.name;
				this.couponMoney = data.coupon_money;
				this.couponId = data.id;

			},
			// 刷新的方法
			refresh() {
				this.curr_page = 0
				this.getList()
			},
			getList() {
				const _this = this
				uni.showLoading({
					title: '加载中...',
					mask: false
				});
				uni.showNavigationBarLoading(); //显示加载动画
				//提交ajax
				//console.log(1111)
				var opt = {
					url: '/order/orderList',
					data: {
						order_estate: _this.order_estate,
						page: ++_this.curr_page,
						// month:_this.monthList.key
					},
					success: function(res) {
						//console.log(res)

						if (res.status == 1) {
							if (_this.curr_page == 1) {
								_this.data.list = res.data.list
								_this.loadingType = 2;

								_this.curr_page = res.data.page
								_this.last_page = res.data.last_page
								uni.hideNavigationBarLoading(); //关闭加载动画
								uni.stopPullDownRefresh(); //得到数据后停止下拉刷新
							} else {
								_this.data.list = _this.data.list.concat(res.data.list)

								_this.curr_page = res.data.page
								_this.last_page = res.data.last_page

								_this.loadingType = 2; //将loadingType归0重置
								uni.hideNavigationBarLoading(); //关闭加载动画
							}
							uni.hideLoading()
						} else {
							_this.data.list = []
							_this.loadingType = 2;
							uni.hideNavigationBarLoading(); //关闭加载动画
							uni.hideLoading()
						}

					}
				};
				//console.log(333)
				_this.$service.GetApi(opt)
			},
			// 获取优惠卷列表
			getCouponList() {
				let _this = this;
				_this.data.couponList.couponList = [];
				let couponObj = JSON.parse(JSON.stringify(_this.couponObj)) //根据这里的价格过滤优惠券
				let oldPrice = parseFloat(couponObj.rent_fee); //商品原价
				// 可叠加状态 
				let opt = {
					url: '/coupon/canUseCoupon',
					data: {
						// related_type:1, //产品类型,配送租赁传1
						// related_id: couponObj.id, //产品id
						// store_id: '' //门店id
					},
					success: function(res) {
						//console.log(res)
						if (res.status == 1) {
							let result = [];
							let overReduce = []; //满减叠加
							let saleReduce = []; //折后可叠加
							let overAndSale = []; //满减和折后组合数组
							let finallyList = [];
							if (res.data.list.length) {
								// 1过滤掉达不到使用优惠卷和满减的数据
								result = res.data.list.filter(function(row) {
									return oldPrice >= row.spend_money

								})
							}

							result.forEach(function(cv) {
								if (cv.type == 1) {
									cv.coupon_money = (oldPrice - oldPrice * (parseFloat(cv.coupon_money)))
										.toFixed(2); //折扣金额
								}
							})
							overReduce = result.filter((res) => {
								// 满减可叠加数组
								return res.type == 0 && res.is_overlay == 1;
							})
							saleReduce = result.filter((res) => {
								// 折扣可叠加数组
								return res.type == 1 && res.is_overlay == 1
							});
							overReduce.forEach(function(res, i) {
								saleReduce.forEach(function(item) {
									// 后面可以在这里过滤组合,折扣后的价格达不到满减的
									let afterSalePrice = oldPrice * (parseFloat(item
									.coupon_money)); //折扣后的价格
									let overPrice = parseFloat(res.spend_money); //满减券
									let salePrice = parseFloat(item.spend_money); //折扣金额
									let sumCoupon = (salePrice + overPrice).toFixed(2); //总的优惠金额
									if (afterSalePrice >= overPrice) {
										overAndSale.push({
											overSaleList: [res, item],
											id: [item.id, res.id].join(','),
											tag_name: '组合券',
											name: item.name + '\n' + res.name,
											related_type_names: res.related_type_names,
											coupon_money: sumCoupon,
											use_start_at: res.use_start_at,
											use_expire_at: res.use_expire_at
										})
									}
								})
							});

							finallyList = JSON.parse(JSON.stringify(result))
							// 将可叠加的满减和折扣进行组合
							finallyList.push(...overAndSale);
							finallyList.sort(compare('coupon_money'));

							_this.data.couponList = JSON.parse(JSON.stringify(finallyList))
							console.log(_this.data.couponList)
						} else {
							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
						}
					}
				}
				_this.$service.GetApi(opt)
			},
			useCoupon() {
				this.showCouponPopup = true;
				this.getCouponList();
			},
			// 滚动切换标签样式
			switchTab: function(e) {
				let that = this;
				this.currentTab = e.detail.current;
				this.checkCor();
			},
			// 点击标题切换当前页时改变样式
			swichNav: function(e) {
				let cur = e.currentTarget.dataset.current;
				if (this.currentTab == cur) {
					return false;
				} else {

					if (cur == 1) {
						//已启用
						this.order_estate = 'used_pending_payment'
					}

					if (cur == 2) {
						//已完成
						this.order_estate = 'completed'
					}

					if (cur == 0) {
						//全部
						this.order_estate = ''
					}

					this.currentTab = cur
					this.curr_page = 0
					this.getList()
				}
			},
			selectMonth() {
				this.$refs.monthPicker.show();
			},
			onConfirm(e) {
				//console.log(e)
				const _this = this
				//console.log(e.index[0])

				if (_this.monthList.key == e.index[0]) {
					return
				}

				_this.monthList.text = e.label
				_this.monthList.key = e.index[0]
				_this.monthList.val = e.value[0]
				_this.getList()
			},
			getPayStore(item) {
				const _this = this
				this.couponObj = JSON.parse(JSON.stringify(item))
				//console.log(item)
				// 清缓存
				_this.data.storeaddress = []
				//清除优惠券缓存
				_this.couponId = 0
				_this.couponName = '优惠券'
				_this.couponMoney = 0

				let coupon = {
					coupon_id: 0,
					name: '优惠券',
					coupon_money: 0
				}
				uni.setStorage({
					key: 'selectCoupon',
					data: coupon,
					success: () => {

					}
				})

				_this.editId = item.id
				_this.editName = item.name
				_this.storeName = item.store_name
				_this.editUseDay = item.use_day
				_this.editRentFee = item.rent_fee
				_this.editRelatedType = item.related_type
				_this.editCash = item.cash
				_this.editCount = item.count
				_this.editPrice = item.price
				_this.editFee = item.fee
				_this.editOutFee = item.out_fee
				_this.editStoreId = item.store_id

				//#ifdef  H5
				jweixin.getLocation({
					type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
					success: function(res) {
						_this.latitude = res.latitude;
						_this.longitude = res.longitude;
						var opt = {
							url: '/order/getPayStore',
							data: {
								lat1: _this.latitude,
								lng1: _this.longitude,
							},
							success: function(res) {
								//console.log(res)
								if (res.status == 1) {
									_this.data.nearbyStore = res.data.list

									//弹出层高度  
									_this.cartsListHeight = _this.calcullateHeight + (21 * (_this.data
										.nearbyStore.length))
									_this.$refs['nearbyStore'].open()
								} else {
									let options = {
										msg: res.message,
										type: 'danger'
									};
									_this.$refs.toast.showTips(options);

								}

							}
						};

						_this.$service.GetApi(opt)
					}
				});
				//#endif
				//#ifdef  MP-WEIXIN || MP-ALIPAY || APP-PLUS
				uni.getLocation({
					//#ifdef  MP-WEIXIN || APP-PLUS
					type: 'gcj02', //返回可以用于uni.openLocation的经纬度
					//#endif
					success: function(res) {
						_this.latitude = res.latitude;
						_this.longitude = res.longitude;
						//console.log(999)
						// _this.latitude = 22.797131;
						// _this.longitude = 108.339878;
						// _this.latitude = 22.804960;
						// _this.longitude = 108.325000;
						var opt = {
							url: '/order/getPayStore',
							data: {
								lat1: _this.latitude,
								lng1: _this.longitude,
								store_id: _this.editId,
								rent_store_id: _this.editStoreId,

							},
							success: function(res) {
								//console.log(res)
								if (res.status == 1) {
									_this.data.nearbyStore = res.data.list
									_this.editDispatchFee = res.data.dispatchFee
									_this.editCount = _this.editCount + _this.editDispatchFee
									//console.log(_this.editDispatchFee)
									//弹出层高度  
									_this.cartsListHeight = _this.calcullateHeight + (21 * (_this.data
										.nearbyStore.length))
									_this.$refs['nearbyStore'].open()
								} else {
									let options = {
										msg: res.message,
										type: 'danger'
									};
									_this.$refs.toast.showTips(options);

								}

							}
						};

						_this.$service.GetApi(opt)
					},
					fail: function() {
						let options = {
							msg: 'GPS未开启',
							type: 'danger'
						};
						_this.$refs.toast.showTips(options);
						return
					}
				});
				//#endif	
			},
			pay() {
				//扫码归还
				const _this = this
				// uni.scanCode({
				//     onlyFromCamera: true,
				//     success: function (res) {	       
				// 		const result = JSON.parse(res.result)
				// 		const return_store_id = result.store_id
				if (_this.data.storeaddress.id == undefined) {
					let options = {
						msg: '未选择门店',
						type: 'danger'
					};
					_this.$refs.toast.showTips(options);
				} else {


					var opt = {
						url: _this.url[_this.editRelatedType == 7 ? 0 : 1],
						data: {
							// return_store_id:_this.data.nearbyStore[_this.current].id,
							return_store_id: _this.data.storeaddress.id,
							id: _this.editId,
							coupon_id: _this.couponId
							// coupon_id:'15,16'

						},
						success: function(res) {
							//console.log(res)
							if (res.status == 1 && res.code == 0) {
								store.dispatch('setOrderNo', res.data.list.order_no)
								// #ifdef  H5
								jweixin.chooseWXPay({
									timestamp: res.data.list
									.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
									nonceStr: res.data.list.nonce_str, // 支付签名随机串，不长于 32 位
									package: 'prepay_id=' + res.data.list
									.prepay_id, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
									signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
									paySign: res.data.list.paySign, // 支付签名
									success: function(res) {
										// 支付成功后的回调函数
										if (res.errMsg == 'requestPayment:ok') {
											let options = {
												msg: '归还成功',
												type: 'green'
											};
											_this.$refs.toast.showTips(options);
											//跳转支付成功页

											// uni.reLaunch({
											// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
											// });
											_this.$refer.setVilit('/pages/pay/success/success')
											let callback = function(url) {
												_this.$refs.popupvLogin.open()
											}
											var data = {
												amount: _this.editRentFee
											}
											_this.$refer.toUrl(callback, data, 'reLaunch')


										}
									},
									fail: err => {
										let opt = {
											url: '/coupon/clearCoupon',
											data: {
												order_no: store.getters.orderNo
												// order_no:"202010171849465f8acc4a24cca"
											},
											success: function(res) {

											},
										}

										_this.$service.GetApi(opt);

									}

								});

								// #endif 
								// #ifdef  MP-WEIXIN  || APP-PLUS
								// _this.payment = res.data.list.payment
								// console.log(res.data.list.order_no)

								// #ifdef  APP-PLUS

								const orderInfo = JSON.stringify({
									appid: res.data.list.appid,
									noncestr: res.data.list.nonce_str,
									package: 'Sign=WXPay',
									partnerid: res.data.list.partnerid,
									prepayid: res.data.list.prepay_id,
									timestamp: res.data.list.timeStamp,
									sign: res.data.list.sign.substring(0, 30),
								})
								// #endif
								uni.requestPayment({
									provider: 'wxpay',
									// #ifdef  MP-WEIXIN
									timeStamp: res.data.list.timeStamp,
									nonceStr: res.data.list.nonce_str,
									package: 'prepay_id=' + res.data.list.prepay_id,
									signType: 'MD5',
									paySign: res.data.list.paySign,
									// #endif
									// #ifdef  APP-PLUS
									orderInfo: orderInfo,
									// #endif
									success: function(res) {
										_this.couponId = 0
										_this.couponName = '优惠券'
										_this.couponMoney = 0
										//清除优惠券缓存
										let coupon = {
											coupon_id: 0,
											name: '优惠券',
											coupon_money: 0
										}
										uni.setStorage({
											key: 'selectCoupon',
											data: coupon,
											success: () => {

											}
										})
										if (res.errMsg == 'requestPayment:ok') {
											let options = {
												msg: '归还成功',
												type: 'green'
											};
											_this.$refs.toast.showTips(options);
											//跳转支付成功页

											// uni.reLaunch({
											// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
											// });
											_this.$refer.setVilit('/pages/pay/success/success')
											let callback = function(url) {
												_this.$refs.popupvLogin.open()
											}
											var data = {
												amount: _this.editRentFee
											}
											_this.$refer.toUrl(callback, data, 'reLaunch')


										}

									},
									fail: function(err) {
										// console.log(store.getters.orderNo)
										let opt = {
											url: '/coupon/clearCoupon',
											data: {
												order_no: store.getters.orderNo
												// order_no:"202010171849465f8acc4a24cca"
											},
											success: function(res) {

											},
										}

										_this.$service.GetApi(opt);
									}
								});
								// #endif 

							} else if (res.status == 1 && res.code == 3000) {
								//月卡内支付
								let options = {
									msg: '归还成功',
									type: 'green'
								};
								_this.$refs.toast.showTips(options);
								//跳转支付成功页

								// uni.reLaunch({
								// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
								// });	
								_this.$refer.setVilit('/pages/pay/success/success')
								let callback = function(url) {
									_this.$refs.popupvLogin.open()
								}
								var data = {
									amount: _this.editRentFee
								}
								_this.$refer.toUrl(callback, data, 'reLaunch')

							} else {
								//清除优惠券缓存
								_this.couponId = 0
								_this.couponName = '优惠券'
								_this.couponMoney = 0
								let coupon = {
									coupon_id: 0,
									name: '优惠券',
									coupon_money: 0
								}
								uni.setStorage({
									key: 'selectCoupon',
									data: coupon,
									success: () => {

									}
								})
								let options = {
									msg: res.message,
									type: 'danger'
								};
								_this.$refs.toast.showTips(options);
								return;
							}


						}
					};

					_this.$service.GetApi(opt)

				}

				//     }
				// });
			},
			radioChange: function(evt) {
				//console.log(this.data.nearbyStore)

				for (let i = 0; i < this.data.nearbyStore.length; i++) {
					if (this.data.nearbyStore[i].id === parseInt(evt.target.value)) {
						this.current = i;
						break;
					}
				}
			},
			//选择自提收货地址
			seleteStore() {
				const _this = this
				console.log("选择收货地址")
				// uni.navigateTo({
				// 	url:'/pages/user/address/returnAddress/return?product_id='+_this.storeProductId
				// })
				_this.$refer.setVilit('/packageUser/pages/user/address/returnAddress/return')
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
				var data = {
					latitude: _this.latitude,
					longitude: _this.longitude,
					editId: _this.editId,
					editStoreId: _this.editStoreId,
				}
				_this.$refer.toUrl(callback, data)
			},
			// 赔付弹框
			lossPayPop(id, productName, selfCustomAmount, cash, relatedType) {
				const _this = this
				_this.lossProductName = productName
				_this.lossOrderId = id
				_this.lossRelatedType = relatedType
				//console.log(selfCustomAmount)
				_this.lossSelfCustomAmount = parseInt(selfCustomAmount) > 0 ? selfCustomAmount : cash
				_this.$refs['lossPopup'].open()
			},
			// 关闭弹框
			closePopup() {
				const _this = this
				_this.$refs['lossPopup'].close()
				_this.$refs['nearbyStore'].close()
			},
			// 赔付
			lossPay() {
				const _this = this

				var opt = {
					url: '/order/lossPay',
					data: {
						id: _this.lossOrderId,
						related_type: _this.lossRelatedType
					},
					success: function(res) {
						//console.log(res)
						if (res.status == 1 && res.code == 0) {
							// #ifdef  H5
							jweixin.chooseWXPay({
								timestamp: res.data.list
								.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
								nonceStr: res.data.list.nonce_str, // 支付签名随机串，不长于 32 位
								package: 'prepay_id=' + res.data.list
								.prepay_id, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
								signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
								paySign: res.data.list.paySign, // 支付签名
								success: function(res) {
									// 支付成功后的回调函数
									if (res.errMsg == 'requestPayment:ok') {
										let options = {
											msg: '赔付成功',
											type: 'green'
										};
										_this.$refs.toast.showTips(options);
										//跳转支付成功页
										setTimeout(function() {
											// uni.reLaunch({
											// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
											// });	
											_this.$refer.setVilit('/pages/pay/success/success')
											let callback = function(url) {
												_this.$refs.popupvLogin.open()
											}
											var data = {
												amount: _this.editRentFee
											}
											_this.$refer.toUrl(callback, data, 'reLaunch')
										}, 2000)

									}
								}
							});

							// #endif 
							// #ifdef  MP-WEIXIN  || APP-PLUS
							// _this.payment = res.data.list.payment
							// _this.order_no = res.data.list.order_no

							// #ifdef  APP-PLUS

							const orderInfo = JSON.stringify({
								appid: res.data.list.appid,
								noncestr: res.data.list.nonce_str,
								package: 'Sign=WXPay',
								partnerid: res.data.list.partnerid,
								prepayid: res.data.list.prepay_id,
								timestamp: res.data.list.timeStamp,
								sign: res.data.list.sign.substring(0, 30),
							})
							// #endif
							uni.requestPayment({
								provider: 'wxpay',
								// #ifdef  MP-WEIXIN
								timeStamp: res.data.list.timeStamp,
								nonceStr: res.data.list.nonce_str,
								package: 'prepay_id=' + res.data.list.prepay_id,
								signType: 'MD5',
								paySign: res.data.list.paySign,
								// #endif
								// #ifdef  APP-PLUS
								orderInfo: orderInfo,
								// #endif
								success: function(res) {

									if (res.errMsg == 'requestPayment:ok') {
										let options = {
											msg: '赔付成功',
											type: 'green'
										};
										_this.$refs.toast.showTips(options);
										//跳转支付成功页
										setTimeout(function() {
											// uni.reLaunch({
											// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
											// });	
											_this.$refer.setVilit('/pages/pay/success/success')
											let callback = function(url) {
												_this.$refs.popupvLogin.open()
											}
											var data = {
												amount: _this.editRentFee
											}
											_this.$refer.toUrl(callback, data, 'reLaunch')
										}, 2000)

									}

								},
								fail: function(err) {
									console.log(store.getters.orderNo)
									//console.log('fail:' + JSON.stringify(err));
								}
							});
							// #endif 

						} else {

							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
							return;
						}


					}
				};

				_this.$service.GetApi(opt)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./order_list.scss";
	@import "./order_swiper.scss";
</style>
